package com.atjinggu.jinggumail.seckill.controller;

import com.atjinggu.jinggumail.common.utils.R;
import com.atjinggu.jinggumail.seckill.service.SeckillService;
import com.atjinggu.jinggumail.seckill.vo.SeckillRedisTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jingming
 * @Type SeckillController.java
 * @Desc
 * @date 2021/3/23 18:08
 */
@Controller
@RequestMapping("/seckill")
public class SeckillController {

    @Autowired
    SeckillService seckillService;

    @ResponseBody
    @GetMapping("/currentSeckill")
    public R getCurrentSeckill(){
       List<SeckillRedisTo> list =  seckillService.getCurrentSeckill();
        return R.ok().setData(list);
    }

    @ResponseBody
    @GetMapping("/getSeckkillInfo/{skuId}")
    public R getSeckkillInfo(@PathVariable("skuId") String skuId){
        SeckillRedisTo to =  seckillService.getSeckkillInfo(skuId);
        return R.ok().setData(to);
    }

    @GetMapping("/killSku")
    public String  killSku(@RequestParam(value = "id")String id,
                           @RequestParam("code")String code,
                           @RequestParam("num") Integer num, Model model){
       String orderSn =   seckillService.killSku(id,code,num);
            model.addAttribute("orderSn",orderSn);
            return "success";
    }
}